//记录捐款人及金额，记录于txt文档中，存储于动态结构数组中，将大于1000金额的金主放在Grand Patrons标题下显示，其余金主在Patrons标题下显示

#include<iostream>
#include<fstream>
#include<string>
#include<vector>

class Contribute
{
public:
	std::string m_name;
	double m_money;
	int m_grade;
};

const std::string FileName = "ContributorsInfo.txt";
void WriteContribute(int c);
void ReadContribute();

int main()
{
	int count;
	std::cout << "Enter the number of contributors: ";
	std::cin >> count;
	std::cin.ignore();
	WriteContribute(count);
	ReadContribute();

	return 0;
}

void WriteContribute(int c)
{
	Contribute cs;
	std::ofstream os;
	os.open("FileName");
	if (!os.is_open())
		std::cout << "Fail to open the file." << std::endl;
	for (int i = 0; i < c; i++)
	{
		std::cout << "Enter the name of contributor: ";
		std::getline(std::cin, cs.m_name);
		std::cout << "Enter the money: ";
		std::cin >> cs.m_money;
		if (cs.m_money >= 1000)
			cs.m_grade = 1;
		else
			cs.m_grade = 2;
		os << cs.m_name << "  " << cs.m_money << "  " << cs.m_grade << std::endl;
		std::cin.ignore();
	}
	os.close();
}

void ReadContribute()
{
	std::ifstream is;
	is.open("FileName");
	if (!is.is_open())
		std::cout << "Fail to open the file." << std::endl;

	std::vector<Contribute> cs1;
	std::vector<Contribute> cs2;
	Contribute cs;
	while (is >> cs.m_name >> cs.m_money >> cs.m_grade)
	{
		if (cs.m_grade == 1)
			cs1.push_back(cs);
		else
			cs2.push_back(cs);
	}
	is.close();

	std::cout << "********Grand Patrons********" << std::endl;
	for (const auto& c : cs1)
		std::cout << c.m_name << "  " << c.m_money << std::endl;

	std::cout << "***********Patrons***********" << std::endl;
	for (const auto& c : cs2)
		std::cout << c.m_name << "  " << c.m_money << std::endl;
}